package com.java1412.goods.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author java1412
 * @since 2023-06-09 10:23:19
 */
@RestController
@RequestMapping(value = "/api/v1/sentinel")
public class SentinelTestController {
    private volatile int total = 0;

    @RequestMapping(value = "/test-sentinel", produces = {"application/json;charset=UTF-8"})
    public Object findByGoodsId() {
        return total++;
    }

    @RequestMapping(value = "/test-sentinel-exception", produces = {"application/json;charset=UTF-8"})
    public Object testSentinelException() {
        int i = (int) (Math.random() * 100);
        if (i > 10) {
            throw new RuntimeException("随机错误");
        }
        return "成功";
    }
}
